<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${path}/pages/">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <title></title>
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<body>
	<div class="layui-fluid">
	<div class="layui-form" style="margin-top: 10px">
		<input type="hidden" id="id" name="id" value="">
  		<div class="layui-form-item">
    		<label class="layui-form-label">原始密码</label>
    		<div class="layui-input-block">
      			<input type="password" id="oldpasswd" name="oldpasswd" value="" lay-verify="required|vpasswd" placeholder="" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		<div class="layui-form-item">
    		<label class="layui-form-label">新密码</label>
    		<div class="layui-input-block">
      			<input type="password" id="newpasswd" name="newpasswd" value="" lay-verify="required|passwd" placeholder="" autocomplete="off" class="layui-input">
    		</div>
  		</div>  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">重复密码</label>
    		<div class="layui-input-block">
      			<input type="password" id="repasswd" name="repasswd"  value="" lay-verify="required|repasswd" placeholder="" autocomplete="off" class="layui-input">
    		</div>
  		</div>  	
  		<div class="layui-form-item layui-hide">
	      	<input type="button" lay-submit lay-filter="lay-form-submit" id="lay-form-submit">
	    </div>
  	</div>
  	</div>
  	<script src="../layui/layui.js"></script>
	<script>
	layui.use(['form','jquery'], function(){
		var form = layui.form;
		var $ = layui.$;
		var passwd;
		$.getJSON('${path}/action/user/verifyPassword', function(data) {
			passwd=data.password;
			
		});	
		
		
		
	 form.verify({			
			 passwd:function(value, item){ //value：表单的值、item：表单的DOM对象
			    if(!new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$").test(value)){
				      return '密码格式不正确';
			    }
			},
			repasswd:function(value ,item){
				if($('#newpasswd').val()!=value){
					return '密码不一致'
				}
			},
			vpasswd:function(value,item){
				if(passwd!=$('#oldpasswd').val()){
					return '密码不正确'
				}
			}
		});   
		
		
		//监听提交
    	form.on('submit(lay-form-submit)', function(data) {
    	
      		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      		
      		//提交ajax成功后，关闭当前弹层并重载表格
      		$.post('${path}/action/user/changePassword', data.field, function(json) {
      			
      			parent.parent.location.href="login.jsp";
      			parent.layer.close(index); //再执行关闭    
      			
      			
      			}, 'JSON');
    	});
		
	});	
	
	</script>
  	
  	
</body>
</html>